package cn.dxj1016.lesson03;

import cn.dxj1016.lesson02.utils.JdbcUtils;

import java.sql.*;

public class TestDelect {
    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        try {
            connection = JdbcUtils.getConnenction();//获取数据库连接
//            区别
//            使用？代替占位符参数
            String sql = "DELETE FROM users WHERE id=?;";
            preparedStatement = connection.prepareStatement(sql);//预编译SQL，先写SQL，然后不执行
//            手动给参数赋值
            preparedStatement.setInt(1, 4);
//            执行
            int i = preparedStatement.executeUpdate();
            if (i > 0) {
                System.out.println("删除成功");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            JdbcUtils.release(connection,preparedStatement,null);
        }
    }
}
